package org.aarboard.nextcloud.api.dicom;

import org.dcm4che3.tool.dcm2jpg.Dcm2Jpg;
import java.io.File;

/**
 * Created by Enzo Cotter on 2022/7/8.
 */

//=================================pom================================================
//<repositories>
//<repository>
//<id>www.dcm4che.org</id>
//<name>dcm4che Repository</name>
//<url>https://www.dcm4che.org/maven2</url>
//</repository>
//<!--        <repository>-->
//<!--            <id>nroduit-mvn-repo-master</id>-->
//<!--            <url>https://raw.github.com/nroduit/mvn-repo/master/</url>-->
//<!--        </repository>-->
//<repository>
//<id>nroduit-mvn-repo-master</id>
//<url>https://github.com/nroduit/mvn-repo/tree/master/</url>
//</repository>
//<repository>
//<id>jboss</id>
//<url>https://repository.jboss.org/nexus/content/groups/public</url>
//</repository>
//</repositories>
//<dependency>
//<groupId>org.dcm4che.tool</groupId>
//<artifactId>dcm4che-tool-dcm2jpg</artifactId>
//<version>5.22.5</version>
//</dependency>
//
//<dependency>
//<groupId>org.dcm4che</groupId>
//<artifactId>dcm4che-core</artifactId>
//<version>5.22.5</version>
//</dependency>
//
//<dependency>
//<groupId>org.dcm4che</groupId>
//<artifactId>dcm4che-image</artifactId>
//<version>5.22.5</version>
//</dependency>
//
//<dependency>
//<groupId>org.dcm4che.tool</groupId>
//<artifactId>dcm4che-tool-common</artifactId>
//<version>5.22.5</version>
//</dependency>
//
//<dependency>
//<groupId>org.dcm4che</groupId>
//<artifactId>dcm4che-imageio</artifactId>
//<version>5.22.5</version>
//</dependency>
//
//<dependency>
//<groupId>org.dcm4che</groupId>
//<artifactId>dcm4che-imageio-opencv</artifactId>
//<version>5.22.5</version>
//</dependency>
//
//<dependency>
//<groupId>org.dcm4che</groupId>
//<artifactId>dcm4che-imageio-rle</artifactId>
//<version>5.22.5</version>
//<scope>runtime</scope>
//</dependency>
//
//<dependency>
//<groupId>org.weasis.opencv</groupId>
//<artifactId>weasis-opencv-core</artifactId>
//<version>3.0.4</version>
//</dependency>
//
//<dependency>
//<groupId>commons-cli</groupId>
//<artifactId>commons-cli</artifactId>
//<version>1.2</version>
//</dependency>

//看报错排除pom中类似的依赖，没有就不管

public class dcm4chetest {

    public static void main(String[] args) throws Exception {
        File dcmFile = new File("D:\\hanby\\ImageJDemo-master\\ImageJDemo-master\\image\\image-000332.dcm");
        File folderFile = new File("D:\\hanby");
        //String  dcmFile ="D:\\hanby\\ImageJDemo-master\\ImageJDemo-master\\image\\test1.dcm";
        dcm2JpgByDcm4che(dcmFile, folderFile);
    }


    /**
     * 通过dcm4che-tool-dcm2jpg将DICOM文件转为jpg文件
     *
     * @param dcmFile    DICOM文件File
     * @param folderFile 存储Image.jpg的文件夹File
     * @return Image.jpg File
     * @throws Exception
     */
    //注意pom中是否有重复的依赖
    //        <dependency>
    //        <groupId>net.sourceforge.tess4j</groupId>
    //        <artifactId>tess4j</artifactId>
    //        <version>2.0.1</version>
    //        <exclusions>
    //            <exclusion>
    //                <groupId>com.sun.jna</groupId>
    //                <artifactId>jna</artifactId>
    //            </exclusion>
    //        </exclusions>
    //    </dependency>
    public static File dcm2JpgByDcm4che(File dcmFile, File folderFile) throws Exception {
        try {
            Dcm2Jpg dcm2Jpg = new Dcm2Jpg();
            dcm2Jpg.initImageWriter("JPEG", null, "com.sun.imageio.plugins.*", null, 1.0);
            String imagePath = folderFile.getAbsolutePath() + "\\aa.jpg";
            File imageFile = new File(imagePath);
            dcm2Jpg.convert(dcmFile, imageFile);
            return imageFile;
        } catch (Exception e) {
            throw new Exception("dcm2jpg 转 JPG 失败！");
        }
    }
}
